<template>
  <div>
    <vxe-toolbar :custom="{immediate:true}">
      <template v-slot:buttons>
        <el-button v-if="$hasPermission('msg:msgBizObject:save')" type="primary" @click="addOrUpdateHandle()">{{
          $t('add') }}</el-button>
        <el-button v-if="$hasPermission('msg:msgBizObject:delete')" type="danger" @click="deleteHandle()">{{
          $t('deleteBatch') }}</el-button>
      </template>
      <template v-slot:tools>
        <!-- <el-button icon="el-icon-search" @click="searchShowHandle()" circle></el-button> -->
        <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
      </template>
    </vxe-toolbar>
    <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize :sort-config="{trigger:'cell'}" @sort-change="sortChange" @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex" :data="dataList">
      <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
      <!-- <vxe-table-column field="ruleId" title="规则ID">
      </vxe-table-column> -->
      <vxe-table-column field="objType" title="对象类型">
        <template slot-scope="scope">
          {{$getDictLabel('MSG_OBJECT_CLASS', scope.row.objType)}}
        </template>
      </vxe-table-column>
      <vxe-table-column field="objName" title="对象名称">
      </vxe-table-column>
      <!-- <vxe-table-column field="updater" title="更新者">
      </vxe-table-column> -->
      <vxe-table-column field="updateDate" title="最后更新时间">
      </vxe-table-column>
      <vxe-table-column title="handle" width="120" show-overflow="false" fixed="right" align="center">
        <template slot-scope="scope">
          <el-button v-if="$hasPermission('msg:msgBizObject:update')" type="text" size="small" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
          <el-button v-if="$hasPermission('msg:msgBizObject:delete')" type="text" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
        </template>
      </vxe-table-column>
    </vxe-table>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './msgBizRule-object-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        activatedIsNeed: false,
        getDataListURL: '/msg/msgBizObject/list',
        getDataListIsPage: false,
        deleteURL: '/msg/msgBizObject',
        deleteIsBatch: true
      },
      dataForm: {
        ruleId: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm = {
          ...this.$refs.addOrUpdate.defaultData,
          id: id,
          ruleId: this.dataForm.ruleId
        }
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
